home *** CD-ROM | disk | FTP | other *** search
/ Windows 95 API Bible / Windows 95 API Bible 3 Disc Set.iso / Win32 API Bible Book 1 of 3 / CHAPTE23 / EX2.C < prev    next >
C/C++ Source or Header  |  1995-03-19  |  2KB  |  59 lines

  1.  
  2.  
  3.  
  4.  
  5.  
  6.  
  7.  
  8.  
  9.  
  10.  
  11.  
  12. #include <genstub.c>
  13.  
  14. LRESULT CALLBACK WndProc (HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
  15. {
  16.    static   UINT      uMessageID;
  17.    static   ATOM      aDataTransmitted;
  18.    switch (uMsg)         // Process windows messages. 
  19.    {
  20.        case WM_CREATE:
  21.                // Register a message for private protocol exchange between application instances.
  22.                uMessageID = RegisterWindowMessage( "generic" );
  23.                // Create atom containing data to exchange.
  24.                aDataTransmitted = GlobalAddAtom( "Transmitted Data" );
  25.                break ;
  26.        case WM_COMMAND:         // Process menu items.
  27.                switch ( LOWORD( wParam ) )
  28.                {
  29.                    case IDM_TEST:
  30.                          // Send the private message to every applicationÆs main window.
  31.                          PostMessage((HWND) -1, uMessageID, aDataTransmitted, 0L );
  32.                          break;
  33.                    case IDM_EXIT:      
  34.                          DestroyWindow (hWnd);
  35.                          break;
  36.                }
  37.                break;
  38.       case WM_DESTROY:      
  39.                GlobalDeleteAtom( aDataTransmitted );
  40.                PostQuitMessage( 0 );
  41.                break;
  42.       default:
  43.                if (uMsg == uMessageID)   /* Check if the message is the registered message. */
  44.                {
  45.                   char cBuf[128];                // Buffer for text output.
  46.                   char cAtomContent[32];         // Buffer for storing atom name in local data.
  47.                   HDC hDC = GetDC( hWnd );
  48.                   GlobalGetAtomName( wParam, cAtomContent, 32 );
  49.                   TextOut( hDC, 0, 0, cBuf, wsprintf( cBuf, "Received %s", (LPSTR) cAtomContent ) );
  50.                   ReleaseDC( hWnd, hDC );
  51.                }
  52.                else
  53.                   return DefWindowProc( hWnd, uMsg, wParam, lParam );
  54.    }
  55.    return (0L);
  56. }
  57.  
  58. #include <about.c>
  59.